/*
 * launcher_robot5.cpp
 *
 */

#include "../middleware/CommunicationDespacho.h"
#include "../channel_common/AgentIdManager.h"
#include "../channel_common/ChannelInterface.h"
#include "../capa_servicios_distribuidos/QueueLauncher.h"
#include "../control/clienteCommon.h"
#include "../application/AdminKeys.h"
#include "../middleware/CommunicationRobot11.h"
#include "../middleware/CommunicationADP.h"
#include "../middleware/CommunicationPrimerCinta.h"
#include "../middleware/CommunicationRobot5.h"
#include "../middleware/CommunicationVendedor.h"
#include "../IPC/ProcessAux.h"
#include "../common/Argv.h"
#include "../middleware/CommunicationAGV.h"

using namespace middleware;

int main(int argc, char**argv)
{
	CLogger::create("Launcher del ADP");
	std::string hostName = "adp_pc";

	Argv args;
	args.pushArg(hostName);

	channel::ChannelInterface::create(hostName);

	ProcessAux::launchProcess2("./out/channel_out_agente",1,args);
	ProcessAux::launchProcess2("./out/channel_in_agente",1,args);

	AdminKeys adminZonaIzq(ZONA_IZQ);
	AdminKeys adminZonaMedio(ZONA_MED);
	AdminKeys adminZonaDer(ZONA_DER);

	CLogger::log("Creando ADP");
	try {
		CommunicationADP::create(CommunicationADP::ADP, hostName);
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Creando AGV");
	try {
		CommunicationAGV::create(adminZonaIzq.getAgvKey(), CommunicationAGV::ADP,hostName);
		CommunicationAGV::create(adminZonaDer.getAgvKey(), CommunicationAGV::ADP,hostName);
		CommunicationAGV::create(adminZonaMedio.getAgvKey(), CommunicationAGV::ADP,hostName);
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Creando robot 11");
	try {
		CommunicationRobot11::create(adminZonaIzq.getRobot11Key());
		CommunicationRobot11::create(adminZonaDer.getRobot11Key());
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}

	CLogger::log("Creando robot 5");
	try {
		CommunicationRobot5::create(CommunicationRobot5::ADP, hostName);
	} catch (Exception e) {CLogger::log(e.what(), LogLevelEnum::FATAL, color::WHITE);}
}
